/**
 * 
 */
package com.wsj.web.action.researchReport;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.wsj.service.IHomeSiteResearchReportFileUploadServ;
import com.wsj.util.exception.BusinessException;
import com.wsj.util.page.PageResultSet;
import com.wsj.web.action.BaseAction;
import com.wsj.web.constant.page.PageContent;
import com.wsj.web.form.researchReport.HomeSiteResearchReportFileUploadForm;
import com.wsj.web.subclass.displayBean.HomeSiteNews.HomeSiteUploadFileExtendBean;
import com.wsj.web.subclass.object.HomeSiteNewsDetailBean;
import com.wsj.web.vo.homeSite.HomeSiteUploadFile;

/**
 * @author fengbin  createTime:2009-12-5
 *
 */
public class HomeSiteReportDetailAction extends BaseAction {

	
	/*********
	 * 研究报告上传服务层
	 */
	 private IHomeSiteResearchReportFileUploadServ homeSiteResearchReportFileUploadServ;
	 
	 


	public IHomeSiteResearchReportFileUploadServ getHomeSiteResearchReportFileUploadServ() {
		return homeSiteResearchReportFileUploadServ;
	}




	public void setHomeSiteResearchReportFileUploadServ(
			IHomeSiteResearchReportFileUploadServ homeSiteResearchReportFileUploadServ) {
		this.homeSiteResearchReportFileUploadServ = homeSiteResearchReportFileUploadServ;
	}




	/**
	 * 通过新闻的id,获取研究报告详情
	 * */
	public ActionForward loadDetailById(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		String toPage ="homeSiteReportDetail";
		
		String idStr = request.getParameter("id");
		
		 
		int id=0;
		if(idStr!=null  && !idStr.equals("")){
			id= Integer.valueOf(idStr);
			
		}
		
		//获取当前研究报告的数据.
		HomeSiteUploadFile  dbHomeSiteUploadFile =this.getHomeSiteResearchReportFileUploadServ().getHomeSiteUploadFileById(id);
		
		request.setAttribute("homeSiteUploadFile", dbHomeSiteUploadFile);
		//获取加精的研究报告
		this.getJJHomeSiteReportList(request,response);
		
		return mapping.findForward(toPage);
		
	}



    /*******
     * 获取加精的试用报告
     * @param request
     * @param response
     */
	private void getJJHomeSiteReportList(HttpServletRequest request, HttpServletResponse response) {
		
		
	      
		HomeSiteResearchReportFileUploadForm homeSiteResearchReportFileUploadForm=new HomeSiteResearchReportFileUploadForm();
		homeSiteResearchReportFileUploadForm.setReportType("jj");
	      
	      try {
	    	  PageResultSet pageResultSet=this.homeSiteResearchReportFileUploadServ.searchResearchReportList(homeSiteResearchReportFileUploadForm,1,10);
				  if(pageResultSet!=null)
					{
					  	// 设置上一页
						request.setAttribute(PageContent.backPage,pageResultSet.getBackPage());
						//下一页
						request.setAttribute(PageContent.nextPage,pageResultSet.getNextPage());
						//当前页
						request.setAttribute(PageContent.curPage,pageResultSet.getCurPage());
						
						//总共页数
						request.setAttribute(PageContent.allPage,pageResultSet.getAllPage());
						//大小
						request.setAttribute(PageContent.pageSize,pageResultSet.getPageSize());
						
						request.setAttribute(PageContent.recordNum, pageResultSet.getRecordNum());
						
						
						request.setAttribute("page",1);
						
						//结果集
						List result=null;
						List exresult=new ArrayList();
						if(pageResultSet!=null)
						{
							result =pageResultSet.getResult();
							if(result!=null){
								for(int i=0;i<result.size();i++){
									
									HomeSiteUploadFile homeSiteUploadFile = (HomeSiteUploadFile)result.get(i);
									
									HomeSiteUploadFileExtendBean homeSiteUploadFileExtendBeanOk=new HomeSiteUploadFileExtendBean();
									try {
										BeanUtils.copyProperties(homeSiteUploadFileExtendBeanOk, homeSiteUploadFile);
										exresult.add(homeSiteUploadFileExtendBeanOk);
									} catch (IllegalAccessException e) {
										e.printStackTrace();
									} catch (InvocationTargetException e) {
										e.printStackTrace();
									}
									
									
								}
								
							}
							
						}
						else
						{
							exresult=new ArrayList();
						}
						
						request.setAttribute("homeSiteUploadFileList", exresult);
						
					}
				  
				  
			} catch (BusinessException e) {
				e.printStackTrace();
			}
	}
}
